
<!-- 
      =============================================
            Quinta Pagina: All gifts
      =============================================     
  -->
  
    
   <div data-role="page"  id="all_gifts" data-theme="f">
       
     
     <script type="text/javascript">
     
     $( "#all_gifts" ).live( "pageinit", function( event ) { // 9fb3cc
       
       $('#all_gifts a.backbutton').prepend('<div style="position: absolute; width: 16px; height: 17px; background: rgb(150, 174, 204); position: absolute; -webkit-transform: rotate(45deg); top: 3px; left: -8px; border: 1px solid rgba(0,0,0, 0.4); -webkit-box-shadow: 0 1px 0 rgba(255,255,255, 0.25), inset 0 1px 1px rgba(0,0,0, 0.2)"></div>');        
  


         var gift = getFromSession();
         

					if (gift != null) {
							if (gift.type == 'single') {
								$('#all_gifts div#blockText').html(
										'<h3 class="ui-title">Ecco il tuo giftshake. </h3>'
									);
								/*$('#all_gifts div[data-role=header] h1').append(
											'<a href="#" class="nextbutton ui-btn-right">Finish</a>');*/


								$('#all_gifts a.nextbutton').button();
								
								$('#all_gifts a.nextbutton').prepend('<div style="position: absolute; width: 16px; height: 17px; background: rgb(150, 174, 204); position: absolute; -webkit-transform: rotate(45deg); top: 3px; right: -8px; border: 1px solid rgba(0,0,0, 0.4); -webkit-box-shadow: 1px 0 0 rgba(255,255,255, 0.25), inset 1px 0 1px rgba(0,0,0, 0.2)"></div>');


							}
							else if (gift.type == 'group') {
								$('#all_gifts div#blockText').html(
										'<h3 class="ui-title">Guarda il gruppo cosa ne pensa del tuo giftshake!</h3>'
									);

								$('#all_gifts a[href=#giftshake-final]').button();
							}
					}


         });
       
       $( "#all_gifts" ).live( "pageshow", function( event ) {

           var gift = getFromSession();

           var allproducts = '';
           var escaped_value;
           var arrProducts = []; 
           var prod;

           $('#all_gifts #block_salva_notifica').css('visibility', 'hidden');
           $('#all_gifts #block_condividi').css('visibility', 'hidden');

           /*
					if (gift != null) {
							if (gift.type == 'single') {
								$('#all_gifts div#blockText').html(
										'<h3 class="ui-title">Ecco il tuo giftshake. </h3>'									   
									);
								$('#all_gifts div[data-role=header] h1').append(
											'<a href="#" class="nextbutton ui-btn-right">Finish</a>');

							}
							else if (gift.type == 'group') {
								$('#all_gifts div#blockText').html(
										'<h3 class="ui-title">Guarda il gruppo cosa ne pensa del tuo giftshake!</h3>' +
									   '<p>' + 
										   '<a href="#giftshake-final" data-role="button" data-inline="true" data-transition="flow" data-theme="b">Condivi adesso!</a>' +
									   '</p>'
									);
							}
					}

*/

           
          if (gift != null) 
           if (gift.products != null) { 
              allproducts = gift.products;
              $('#all_gifts #gifts_in_shake').css('visibility', 'visible');
              $('#all_gifts #gifts_in_shake').html(allproducts.length); 
            }
                   

          
          
          
          $.each( allproducts, function( key, value ) {
              escaped_value = value.replace(/(:|\.|\[|\])/g,'\\$1');   
              
              prod = {};
              
              // var index = value.match(/\[(\d+)\]/);
              var ptype = value.match(/\[([a-z\-]+)\]/);   // riviste, ..
              var pcod = value.match(/\[([0-9]+)\]/);  // 001,002,..
              
              //alert(typeproduct[1] + ' ' + idnum[1]);

              //alert(ptype);
              
              
              
              // costruisco l'array delle scelte che poi lo passo in ajax allo script
              // per reperire i prodotti
              
              prod['type'] = ptype[1];
              prod['cod'] = pcod[1];
              

              arrProducts.push(prod);  // collection of objects (riviste, 001)

            
            });
            
            //alert(JSON.stringify(arrProducts));
            
            
            $.ajax({ url: "script_get_products.php",
            type: 'POST',
            //dataType: 'json',
            data: {products: JSON.stringify(arrProducts)}, //"item_type=" + param,
            success: function(data) {          
              //alert(data);
                
              
                $("#all_gifts div[data-role=content] ul").html(data);
                $("#all_gifts div[data-role=content] ul" ).listview("refresh");                
                $("#all_gifts div[data-role=content]").iscrollview("refresh");

                // ho caricato i prodotti, abilito il pulsante di notifica (solo se single gift)
                if (gift.type === 'single')
                    $('#all_gifts #block_salva_notifica').css('visibility', 'initial');
                else if (gift.type === 'group')
                    $('#all_gifts #block_condividi').css('visibility', 'initial');

              }
            }); // end ajax
            
          });
          
          
         $('#all_gifts a[name=deleteProd]').live('click',function() {           
           var prodId_to_del = $(this).attr("data-parm");
           
           var ptype = prodId_to_del.match(/\[([a-z\-]+)\]/)[1];   // riviste, ..
           var pcod = prodId_to_del.match(/\[([0-9]+)\]/)[1];  // 001,002,..
           
           // oppure risalgo dal this al parent li e lo elimino senza passare parametri
           $('#all_gifts li#products\\[' + ptype + '\\]\\['+ pcod +'\\]').remove();  
           
           
           
           // todo: aggiornare la sessione e aggiornare il count prodotti
           var gift = getFromSession();
           var arrProducts = [];
           
           if (gift != null) {
               arrProducts = gift.products;          
               
               $.each( arrProducts, function( key, productId ) {             
                 if(productId == prodId_to_del) {
                   arrProducts.splice(key,1);  // elimino dall'array l'elemento
                   sessionStorage.setItem('gift', JSON.stringify(gift) );
                    }
                });
             }
            
            updateProductSelection('#all_gifts'); 
            
         }); 
       
     </script>
     
     
     
     <!-- <script>
       $( "#scheda_prodotto" ).live( "pageinit", function( event ) {       
          $('#scheda_prodotto a.backbutton').prepend('<div style="position: absolute; width: 16px; height: 17px; background: rgb(150, 174, 204); position: absolute; -webkit-transform: rotate(45deg); top: 3px; left: -8px; border: 1px solid rgba(0,0,0, 0.4); -webkit-box-shadow: 0 1px 0 rgba(255,255,255, 0.25), inset 0 1px 1px rgba(0,0,0, 0.2)"></div>');               
      });
    </script> -->
    
    <!-- <div data-role="popup" id="popupDialog" data-overlay-theme="a" data-theme="c" data-dismissible="false" style="max-width:250px; height: 150px;" class="ui-corner-all">
    <div data-role="header" data-theme="f" class="ui-corner-top">
        <h1>Share</h1>
    </div>
    <div data-role="content" data-theme="d" class="ui-corner-bottom ui-content" style="height: 150px;"
        <h3 class="ui-title">Guarda il gruppo cosa ne pensa del tuo giftshake!</h3>
        <p>Condividi adesso?</p>
        <a href="#" data-role="button" data-inline="true" data-rel="back" data-transition="flow" data-theme="b">Ok!</a>
        <a href="#" data-role="button" data-inline="true" data-rel="back" data-theme="f">Dopo</a>
    </div>
  </div> -->


     <style>

         .white, .white a {
             background-color: #FFFFFF !important;
             background-image: none !important;
         }

         .white a {
             border-top: none !important;
             border-bottom: none !important;
         }

     </style>

     
    <div data-role="header" data-theme="f">
      <a href="#page_giftlist" class="backbutton">Continua</a>
      <h1>Il tuo Giftshake</h1>
      <!-- <a id="" href="#popupDialog" class="rectbutton" data-rel="popup" data-position-to="window"  data-inline="true" data-transition="pop">Concludi</a> -->
    </div>
    <div data-role="content" data-iscroll="">
      <!-- content via ajax -->
      
     <div id="blockText"> 
     <!--  dynamic via js --> 
     </div>
          
      <ul  data-split-icon="delete" data-split-theme="d" data-inset="true" data-role="listview">
      
      <!--  dynamic content via js -->
      
      </ul>

        <div style="visibility: hidden " id="block_condividi">
            <p>
                <a href="#giftshake-final" data-role="button"  data-transition="flow" data-theme="b">Condividi </a>
            </p>
        </div>

      <div style="visibility: hidden" id="block_salva_notifica">
      <p>
        <fieldset class="ui-grid-a">
            <div class="ui-block-a">
                <a href="#" data-role="button" data-transition="flow" data-theme="c">Salva</a>
            </div>
            <div class="ui-block-b">
                <a href="page.survey.php" rel="external" data-role="button" data-transition="flow" data-theme="b">Invia</a>
            </div>
        </fieldset>
	  </p>
      </div>
      
       
      
    </div> <!-- end content -->

      
     
    <div data-role="footer" data-position="fixed" class="nav-glyphish-example" data-theme=c>
        <div data-role="navbar" class="nav-glyphish-example" >
          <ul>
            <li><a href="home.php" rel="external" id="home" data-icon="custom"><h4>Home</h4></a></li>
            <li><a href="#" id="search" data-icon="custom"><h4>Search</h4></a></li>
            <li><a href="#" id="gift" data-icon="custom">
                <span id="gifts_in_shake" class="ui-li-count" style="left:42px; top:-9px; visibility: hidden "></span>
                <h4>Giftshake</h4>
            </a>
            </li>
            <li><a href="#" id="wishlist" data-icon="custom"><h4>Preferiti</h4></a></li>
          </ul>
        </div>
        
        <!-- <ul style="list-style: none; padding: 0">
        <li>
         <a data-inline="true" href="" 
             style ="text-decoration: none; font-size: 13px; color: #999999 ">Giftshake © 2013</a>       
         
         <a data-inline="true" href="" 
             style ="text-decoration: none; padding-left: 20px; font-size: 13px; color: #999999" >Guida
         </a>
        </li>
     </ul> -->
        
      </div> <!-- footer -->   
  </div>